package com.approval.approvalapp.index.dbsx.tshf.adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.approval.approvalapp.R;
import com.approval.approvalapp.bean.TshfdbBean;
import com.approval.approvalapp.index.dbsx.tshf.TshfxqYbActivity;

import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by louyulin on 2019/4/29.
 */

public class TshfybAdapter extends RecyclerView.Adapter<TshfybAdapter.Holder> {


    List<TshfdbBean> tshfdbBeanList;

    public void setTshfdbBeanList(List<TshfdbBean> tshfdbBeanList) {
        this.tshfdbBeanList = tshfdbBeanList;
        notifyDataSetChanged();
    }

    Context context;


    @Override
    public Holder onCreateViewHolder(ViewGroup parent, int viewType) {
        context = parent.getContext();
        View view = LayoutInflater.from(context).inflate(R.layout.item_tshfyb,parent,false);
        Holder holder = new Holder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(Holder holder, final int position) {
        holder.tv1.setText(tshfdbBeanList.get(position).getTitle());

        holder.tv5.setText(tshfdbBeanList.get(position).getSubmitdate());

        holder.tv4.setText("咨询单位: " + tshfdbBeanList.get(position).getSubmittarget());
        holder.tv3.setText("咨询人: " + tshfdbBeanList.get(position).getSubmitusername());

        holder.root.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent();
                intent.setClass(context, TshfxqYbActivity.class);
                intent.putExtra("title",tshfdbBeanList.get(position).getTitle());
                intent.putExtra("zxr",tshfdbBeanList.get(position).getSubmitusername());
                intent.putExtra("zxdw",tshfdbBeanList.get(position).getSubmittarget());
                intent.putExtra("zxsj",tshfdbBeanList.get(position).getSubmitdate());
                intent.putExtra("applyid",tshfdbBeanList.get(position).getApplyid());
                context.startActivity(intent);
            }
        });
    }

    @Override
    public int getItemCount() {
        if (tshfdbBeanList == null){
            return 0;
        }else {
            return tshfdbBeanList.size();
        }
    }

    class Holder extends RecyclerView.ViewHolder{
        @Bind(R.id.tv1)
        TextView tv1;
        @Bind(R.id.tv3)
        TextView tv3;
        @Bind(R.id.tv4)
        TextView tv4;
        @Bind(R.id.tv5)
        TextView tv5;
        @Bind(R.id.root)
        LinearLayout root;
        public Holder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }
}
